package com.gitee.feizns.quickstart.ding.talk.api.v10.yida.forms.instances;

import com.aliyun.dingtalkyida_1_0.Client;
import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders;
import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest;
import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasResponse;
import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasResponseBody;
import com.aliyun.teautil.models.RuntimeOptions;
import com.gitee.feizns.quickstart.ding.talk.client.Clients;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * 查询表单实例数据（/v1.0/yida/forms/instances/search）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/querying-form-instance-data">查询表单实例数据（/v1.0/yida/forms/instances/search）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/querying-form-instance-data">服务端API 宜搭应用开发 表单 查询表单实例数据</a>
 * @author feizns
 * @since 2024/4/1
 */
public class Search {

    /**
     * 查询表单实例数据
     * @param accessToken 访问凭据
     * @param req {@link SearchFormDatasRequest}
     * @return {@link SearchFormDatasResponseBody}
     */
    @SneakyThrows
    public static SearchFormDatasResponseBody execute(@NotNull String accessToken,
                                                      @Nullable SearchFormDatasRequest req) {
        //客户端
        Client client = Clients.get(Client.class);
        //请求头
        SearchFormDatasHeaders headers = headers(accessToken);
        //请求
        SearchFormDatasResponse resp = client.searchFormDatasWithOptions(req, headers, new RuntimeOptions());
        return resp.getBody();
    }

    /**
     * 请求头
     * @param accessToken 访问凭据
     * @return {@link SearchFormDatasHeaders}
     */
    public static SearchFormDatasHeaders headers(@NotNull String accessToken) {
        SearchFormDatasHeaders headers = new SearchFormDatasHeaders();
        headers.xAcsDingtalkAccessToken = accessToken;
        return headers;
    }

}
